import { DisposeView } from "../../../mvc/core/DisposeView";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { AIManager } from "../../scene/ai/AIManager";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { Language } from "../../../../extend/language/Language";
import { ECareer } from "../../../../Message/Public/ECareer";
import { Cache } from "../../cache/Cache";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { CareerUtil } from "../common/util/CareerUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ResFileConst } from "../../resource/ResFileConst";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { WarehouseGoodsItemRenderer } from "../guild/resourceAllocation/itemRenderer/WarehouseGoodsItemRenderer";
import { MultiTabBarSelectItemEffect } from "../../../component/multiTabBar/MultiTabBarSelectItemEffect";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GTextFiledBitmap } from "../../../../com/mui/controls/GTextFiledBitmap";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { MultiTabBar } from "../../../component/multiTabBar/MultiTabBar";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
type int = number;
//class LadderBattlefieldInfoView
    
    export  class LadderBattlefieldInfoView extends DisposeView
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */onMultiTabBarChangeHandler(arg1: MuiEvent): void
        {
            var loc1=this._multiTabBar.selectedIndex;
            Dispatcher.dispatchEvent(new DataEvent(EventName.LadderBattlefieldGetToplistByCareer, loc1));
            return;
        }

        /* internal  */onExchangeLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._npcTarget) 
            {
                hide();
                AIManager.onAutoPathAIControl(this._npcTarget);
            }
            return;
        }

        /* internal  */get rewardsData(): DataProvider
        {
            var loc1=new DataProvider();
            var loc2=Language.getString(28828).split(",");
            var loc3=loc2.length;
            var loc4=0;
            while (loc4 < loc3) 
            {
                loc1.addItem(int(loc2[loc4]));
                ++loc4;
            }
            return loc1;
        }

        /* internal  */getIndexByCareer(arg1: int): int
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case ECareer._ECareerWarriorD:
                {
                    return 0;
                }
                case ECareer._ECareerStabber:
                {
                    return 1;
                }
                case ECareer._ECareerPriest:
                {
                    return 2;
                }
                case ECareer._ECareerIceMage:
                {
                    return 3;
                }
            }
            return -1;
        }

        public setMyInfo(): void
        {
            var loc1=Cache.instance.ladderBattlefield.myInfo;
            if (loc1.ladderCareer > 0) 
            {
                this._career.htmlText = Language.getStringByParam(28808, HTMLUtil.addColor(CareerUtil.getCareerName(loc1.ladderCareer), GlobalStyle.color1));
            }
            else 
            {
                this._career.htmlText = Language.getStringByParam(28808, HTMLUtil.addColor(Language.getString(28826), GlobalStyle.color1));
            }
            if (loc1.todayNum <= 0) 
            {
                this._winRate.htmlText = Language.getStringByParam(28811, HTMLUtil.addColor("0%", GlobalStyle.color1));
            }
            else 
            {
                this._winRate.htmlText = Language.getStringByParam(28811, HTMLUtil.addColor(Math.floor(loc1.winNum / loc1.todayNum * 100) + "%", GlobalStyle.color1));
            }
            this._ranking.htmlText = Language.getStringByParam(28809, HTMLUtil.addColor(loc1.rankCross.toString(), GlobalStyle.color1));
            this._integral.htmlText = Language.getStringByParam(28810, HTMLUtil.addColor(loc1.mark.toString(), GlobalStyle.color1));
            return;
        }

        public setMultiTabBarIndex(): void
        {
            var loc1=Cache.instance.ladderBattlefield.ladderCareer;
            if (this._isLoadCom && loc1 > 0) 
            {
                this._multiTabBar.selectedIndex = this.getIndexByCareer(loc1);
            }
            return;
        }

        /* internal  */onLoadResHandler(): void
        {
            this._isLoadCom = true;
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.LadderBattlefieldTxt1, 60, 138, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.LadderBattlefieldTxt2, 53, 235, this));
            pushUIToDisposeVec(ObjCreate.createGBitmap(ImagesConst.LadderBattlefieldTxt3, 20, 8, this));
            this._multiTabBar.dataProvider = [ResFileConst.LadderBattlefieldCareer1, ResFileConst.LadderBattlefieldCareer2, ResFileConst.LadderBattlefieldCareer3, ResFileConst.LadderBattlefieldCareer4];
            this.setMultiTabBarIndex();
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(ObjCreate.createBg(0, 0, 217, 400, this));
            this._career = ObjCreate.createGTextFiledBitmap("", 35, 35, 220, 20, this, GlobalStyle._textFormat2);
            this._ranking = ObjCreate.createGTextFiledBitmap("", 35, 55, 220, 20, this, GlobalStyle._textFormat2);
            this._integral = ObjCreate.createGTextFiledBitmap("", 35, 75, 220, 20, this, GlobalStyle._textFormat2);
            this._winRate = ObjCreate.createGTextFiledBitmap("", 35, 95, 220, 20, this, GlobalStyle._textFormat2);
            pushUIToDisposeVec(ObjCreate.createBg(9, 130, 200, 2, this, ImagesConst.SplitLine));
            pushUIToDisposeVec(ObjCreate.createBg(9, 225, 200, 2, this, ImagesConst.SplitLine));
            pushUIToDisposeVec(ObjCreate.createBg(0, 158, 220, 45, this, ImagesConst.FightingStrgBg));
            if (!this._npcTarget) 
            {
                this._npcTarget = Cache.instance.scene.getNpcByEffect2(ENpcEffect._ENpcEffectLadderShop, 801016);
            }
            var loc1=ObjCreate.createGTextField("", 160, 204, 28, 20, this, GlobalStyle.textFormatWhite, true);
            loc1.htmlText = HTMLUtil.addLink(Language.getString(28812), GlobalStyle.color5);
            loc1.configEventListener(flash.events.TextEvent.LINK, this.onExchangeLinkHandler);
            pushUIToDisposeVec(loc1);
            if (!this._rewards) 
            {
                this._rewards = ObjCreate.createTileList(27, 162, 200, 50);
                this._rewards.scrollPolicy = ScrollPolicy.OFF;
                this._rewards.columnWidth = 41;
                this._rewards.rowHeight = 41;
                this._rewards.setStyle("cellRenderer", WarehouseGoodsItemRenderer);
                this._rewards.dataProvider = this.rewardsData;
                this._rewards.drawNow();
            }
            this.addChild(this._rewards);
            this._multiTabBar = ObjCreate.createMultiTabBar(null, 8, 263, 95, 63, 2, 2, 10, 7, false, this, this.onMultiTabBarChangeHandler, MultiTabBarSelectItemEffect.GLOW);
            LoaderHelp.addResCallBack(ResFileConst.LadderBattlefield, this.onLoadResHandler);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            this._isLoadCom = false;
            this._career.dispose(arg1);
            this._ranking.dispose(arg1);
            this._integral.dispose(arg1);
            this._winRate.dispose(arg1);
            this._multiTabBar.dispose(arg1);
            this._career = null;
            this._ranking = null;
            this._integral = null;
            this._winRate = null;
            this._multiTabBar = null;
            return;
        }

        /* internal */ /* var */_career: GTextFiledBitmap;

        /* internal */ /* var */_ranking: GTextFiledBitmap;

        /* internal */ /* var */_integral: GTextFiledBitmap;

        /* internal */ /* var */_winRate: GTextFiledBitmap;

        /* internal */ /* var */_rewards: GTileList;

        /* internal */ /* var */_multiTabBar: MultiTabBar;

        /* internal */ /* var */_npcTarget: TaskTargetInfo;

        /* internal */ /* var */_isLoadCom: Boolean;
    }
